<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace Qcloud\Cos;

class Md5Listener implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
    private $signature;
    public static function getSubscribedEvents()
    {
        return ["command.after_prepare" => "onCommandAfterPrepare"];
    }
    public function __construct(Signature $signature)
    {
        $this->signature = $signature;
    }
    public function onCommandAfterPrepare(\Guzzle\Common\Event $event)
    {
        $command = $event["command"];
        $operation = $command->getOperation();
        if($operation->getData("contentMd5")) {
            $this->addMd5($command);
        } elseif($operation->hasParam("ContentMD5")) {
            $value = $command["ContentMD5"];
            if($value === true || $value === NULL && !$this->signature instanceof SignatureV4) {
                $this->addMd5($command);
            }
        }
    }
    private function addMd5(\Guzzle\Service\Command\CommandInterface $command)
    {
        $request = $command->getRequest();
        $body = $request->getBody();
        if($body && 0 < $body->getSize() && false !== ($md5 = $body->getContentMd5(true, true))) {
            $request->setHeader("Content-MD5", $md5);
        }
    }
}

?>